import threading
from concurrent.futures import ThreadPoolExecutor
from elasticsearch import Elasticsearch

es = Elasticsearch("192.168.2.159")


def insert_line(file_path):
	print("execute file-->", file_path)

	with open(file_path, 'r', encoding='utf-8') as f:
		for line in f.readlines():
			if len(line) < 2:
				continue
			res = es.index(index="big", doc_type='txt', body={"sentence": line.strip()})
			print(res)
	print("execute file success-->", file_path)


# 创建一个包含2条线程的线程池
pool = ThreadPoolExecutor(max_workers=11)
# 向线程池提交一个task, 50会作为action()函数的参数
future1 = pool.submit(insert_line, "F:\\txt\\wffs.txt")
# 向线程池再提交一个task, 100会作为action()函数的参数
future2 = pool.submit(insert_line, "F:\\txt\\js.txt")
future3 = pool.submit(insert_line, "F:\\txt\\jstm.txt")
future4 = pool.submit(insert_line, "F:\\txt\\tsxk.txt")
future5 = pool.submit(insert_line, "F:\\txt\\xylz.txt")
future6 = pool.submit(insert_line, "F:\\txt\\ztj.txt")
future7 = pool.submit(insert_line, "F:\\txt\\asjct.txt")
future8 = pool.submit(insert_line, "F:\\txt\\clks.txt")
future9 = pool.submit(insert_line, "F:\\txt\\dpcq.txt")
future10 = pool.submit(insert_line, "F:\\txt\\dldl.txt")
future11 = pool.submit(insert_line, "F:\\txt\\xcb.txt")
